home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 26 / CU Amiga Magazine's Super CD-ROM 26 (1998)(EMAP Images)(GB)[!][issue 1998-09].iso / CUCD / Utilities / XPK / Developers / Include / ASM / xpk / xpkLibHeader.i < prev    next >
Text File  |  1998-06-27  |  6KB  |  193 lines

  1.  
  2. **************** $VER: xpkLibHeader.i 1.5 (27.06.1998) *******************
  3.  
  4.     NOLIST
  5.     INCLUDE "exec/types.i"
  6.     INCLUDE "exec/execbase.i"
  7.     INCLUDE "exec/initializers.i"
  8.     INCLUDE "exec/libraries.i"
  9.     INCLUDE "exec/lists.i"
  10.     INCLUDE "exec/alerts.i"
  11.     INCLUDE "exec/resident.i"
  12.     INCLUDE "dos/dos.i"
  13.     INCLUDE    "lvo.i"        ; contains all needed lvo's
  14.     LIST
  15.  
  16. **************************************************************************
  17.  
  18. ;    XDEF    InitTable
  19. ;    XDEF    Open
  20. ;    XDEF    Close
  21. ;    XDEF    Expunge
  22. ;    XDEF    Null
  23. ;    XDEF    LibName
  24.  
  25. **************************************************************************
  26.  
  27.     SECTION    "0", Code
  28. Start    MOVEQ    #-1,d0    ; return an error in case someone
  29.     RTS        ; tried to run as a program
  30.  
  31. ; A romtag structure.  Both "exec" and "ramlib" look for this structure to
  32. ; discover magic constants about you (such as where to start running you
  33. ; from...).
  34.  
  35. RomTag        DC.W    RTC_MATCHWORD    ; UWORD rt_MatchWord
  36.         DC.L    RomTag        ; APTR  rt_MatchTag
  37.         DC.L    EndCode        ; APTR  rt_EndSkip
  38.         DC.B    RTF_AUTOINIT    ; UBYTE rt_Flags
  39.         DC.B    VERSION        ; UBYTE rt_Version
  40.         DC.B    NT_LIBRARY    ; UBYTE rt_type
  41.         DC.B    0        ; BYTE  rt_Pri
  42.         DC.L    LibName        ; APTR  rt_Name
  43.         DC.L    IDString    ; APTR  rt_IDString
  44.         DC.L    InitTable    ; APTR  rt_Init  table for InitResident()
  45.  
  46. ; The romtag specified that we were "RTF_AUTOINIT". This means that the
  47. ; rt_Init structure member points to one of these tables below. If the
  48. ; AUTOINIT bit was not set then RT_INIT would point to a routine to run.
  49.  
  50. InitTable:
  51.     DC.L    LIB_SIZE        ; size of library base data space
  52.     DC.L    funcTable        ; pointer to function initializers
  53.     DC.L    dataTable        ; pointer to data initializers
  54.     DC.L    initRoutine        ; routine to run
  55.  
  56. funcTable:
  57. ;------ standard system routines
  58.     DC.L    Open
  59.     DC.L    Close
  60.     DC.L    Expunge
  61.     DC.L    Null
  62. ;------ the library definitions
  63.     DC.L    _XpksPackerInfo
  64.     DC.L    _XpksPackChunk
  65.     DC.L    _XpksPackFree
  66.     DC.L    _XpksPackReset
  67.     DC.L    _XpksUnpackChunk
  68.     DC.L    _XpksUnpackFree
  69. ;------ function table end marker
  70.     DC.L    -1
  71.  
  72. ; The data table initializes static data structures. The format is specified
  73. ; in exec/InitStruct routine's manual pages. The INITBYTE/INITWORD/INITLONG
  74. ; routines are in the file "exec/initializers.i". The first argument is the
  75. ; offset from the library base for this byte/word/long. The second argument
  76. ; is the value to put in that cell. The table is null terminated.
  77.  
  78. dataTable:
  79.     INITBYTE    LN_TYPE,NT_LIBRARY
  80.     INITLONG    LN_NAME,LibName
  81.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED!LIBF_CHANGED
  82.     INITWORD    LIB_VERSION,VERSION
  83.     INITWORD    LIB_REVISION,REVISION
  84.     INITLONG    LIB_IDSTRING,IDString
  85.     DC.L        0
  86.  
  87. ; This routine gets called after the library has been allocated. The library
  88. ; pointer is in D0. The segment list is in A0. If it returns non-zero then
  89. ; the library will be linked into the library list.
  90.  
  91. SegList        DC.L    0
  92. initRoutine:
  93. ;------ get the library pointer into a convenient A register
  94.     MOVE.L    A5,-(A7)
  95.     MOVEA.L    D0,A5
  96. ;------ save a pointer to our loaded code
  97.     MOVE.L    A0,SegList
  98. ;
  99. ; specific openings here
  100. ;
  101.     JSR    _xInitCode
  102.     TST.L    D0
  103.     BNE.B    .kill
  104.     MOVE.L    A5,D0
  105. .end    MOVEA.L    (A7)+,A5
  106.     RTS
  107. .kill    JSR    _xExitCode
  108.     MOVEQ    #0,D0
  109.     BRA.B    .end
  110.  
  111. ; here begins the system interface commands. When the user calls
  112. ; OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  113. ; into a call to the following routines (Open/Close/Expunge). Exec has
  114. ; already put our library pointer in A6 for us. Exec has turned off task
  115. ; switching while in these routines (via Forbid/Permit), so we should not
  116. ; take too long in them.
  117.  
  118. ; Open returns the library pointer in D0 if the open was successful. If the
  119. ; open failed then null is returned. It might fail if we allocated memory
  120. ; on each open, or if only one application could have the library open at
  121. ; a time...
  122.  
  123. Open:        ; (libptr:A6, version:D0)
  124. ;------ mark us as having another opener
  125.     ADDQ.W    #1,LIB_OPENCNT(A6)
  126.     BCLR    #LIBB_DELEXP,LIB_FLAGS(A6)
  127.     MOVE.L    A6,D0
  128.     RTS
  129.  
  130. ; There are two different things that might be returned from the Close
  131. ; routine. If the library is no longer open and there is a delayed expunge
  132. ; then Close should return the segment list (as given to Init). Otherwise
  133. ; close should return NULL.
  134.  
  135. Close:        ; (libptr:A6)
  136. ;------ set the return value
  137.     MOVEQ    #0,D0
  138. ;------ mark us as having one fewer openers
  139.     SUBQ.W   #1,LIB_OPENCNT(A6)
  140. ;------ see if there is anyone left with us open
  141.     BNE.B    OneLeft
  142. ;------ do the expunge
  143.     BTST    #LIBB_DELEXP,LIB_FLAGS(a6)
  144.     BEQ.B    DelExp
  145.     BSR.B    Expunge
  146. OneLeft
  147. DelExp    RTS
  148.  
  149. ; There are two different things that might be returned from the Expunge
  150. ; routine. If the library is no longer open then Expunge should return the
  151. ; segment list (as given to Init). Otherwise Expunge should set the delayed
  152. ; expunge flag and return NULL.
  153. ; One other important note: because Expunge is called from the memory
  154. ; allocator, it may NEVER Wait() or otherwise take long time to complete.
  155.  
  156. Expunge:    ; (libptr: A6)
  157.     MOVEM.L    D2/A5/A6,-(A7)
  158.     MOVEA.L    A6,A5
  159.     MOVEA.L    4.W,A6
  160. ;------ see if anyone has us open
  161.     TST.W    LIB_OPENCNT(A5)
  162.     BEQ.B    DoIt
  163.     BSET    #LIBB_DELEXP,LIB_FLAGS(A5)
  164.     MOVEQ    #0,D0
  165.     BRA.B    Expunge_End
  166. DoIt
  167. ;------ go ahead and get rid of us.  Store our seglist in D2
  168.     MOVE.L    SegList(PC),D2
  169. ;------ unlink from library list
  170.     MOVEA.L    A5,A1
  171.     JSR    _LVORemove(A6)
  172. ;
  173. ; device specific closings here...
  174.     JSR    _xExitCode
  175. ;
  176. ;------ free our memory
  177.     MOVEQ    #0,D0
  178.     MOVEA.L    A5,A1
  179.     MOVE.W    LIB_NEGSIZE(A5),D0
  180.     SUBA.L    D0,A1
  181.     ADD.W    LIB_POSSIZE(A5),D0
  182.     MOVEA.L    4.W,A6
  183.     JSR    _LVOFreeMem(A6)
  184. ;------ set up our return value
  185.     MOVE.L    D2,D0
  186.  
  187. Expunge_End:
  188.     MOVEM.L    (A7)+,D2/A5/A6
  189.     RTS
  190.  
  191. Null:    MOVEQ    #0,D0
  192. EndCode    RTS
  193.